package lcr;

import java.util.TreeSet;

public class Test0057 {
}

class Solution0057_1 {
    public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
        TreeSet<Long> set = new TreeSet<Long>();
        int length = nums.length;
        for (int i = 0; i < length; i++) {
            if (i > k) {
                set.remove((long) nums[i - k - 1]);
            }
            Long adjacent = set.ceiling((long) nums[i] - t);
            if (adjacent != null && adjacent <= (long) nums[i] + t) {
                return true;
            }
            set.add((long) nums[i]);
        }
        return false;
    }
}
